import pandas as pd
import numpy as np
import time
import re
import csv
import sys


def task1():
    file1=pd.read_csv(r'c:\Users\86157\Desktop\gaze.csv')
    file1 = np.array(file1)
    data=[]
    for item in file1:
        sh = float(item[2])
        if 0.9 <= sh:
            data.append(item)
    print(data)

def task2():
    file1=pd.read_csv(r'c:\Users\86157\Desktop\gaze.csv')
    file1 = np.array(file1)
    data1=[]
    data2=[]
    mean1 = sum(item[3])/len(item[3])
    mean2 = sum(item[4])/len(item[4])
    sigama1 = pow(sum(pow(item[3]-mean1,2))/len(item[3]),0.5)
    sigama2 = pow(sum(pow(item[4]-mean1,2))/len(item[4]),0.5)
    sh1 = float(item[3])
    sh2 = float(item[4])
    for item in file1:
        if mean1 - 3*sigama1 < sh1 < mean1 + 3*sigama1:
            data1.append(item)
    print(data1)
    for item in file1:
        if mean2 - 3*sigama2 < sh2 < mean2 + 3*sigama2:
            data2.append(item)
    print(data2)

def task3():
    file1=pd.read_csv(r'c:\Users\86157\Desktop\gaze.csv')
    data=[]
    for item in range(0,len(file1)):
        row = data.iloc[item][0]
        timestruct = time.strptime(row, "%Y/%M/%D %H:%M:%S")
        timestamp = int(time.mktime(timestruct))
        data.append(timestamp)
    print(data)

def task4():
    file1=pd.read_csv(r'c:\Users\86157\Desktop\gaze.csv')
    length = len(file1['gaze_timestamp'])
    data = file1['gaze_timestamp']
    maxtime = max(data)
    mintime = min(data)
    meantime = (maxtime - mintime)/length
    rate = 1/meantime
    print(rate)

def task5():
    file1=pd.read_csv(r'c:\Users\86157\Desktop\gaze.csv')
    file1['gaze_timestamp'] = pd.to_datetime(file1['gaze_timestamp'].values, unit='ms')
    file1 = file1.resample('10ms', on='gaze_timestamp').mean()
    print(file1[0: 20])


    





